home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / mcode_01 / source / function.s next >
Text File  |  1995-04-27  |  5KB  |  132 lines

  1. * Program     : The is a general collection of the functions that
  2. *          are used most of the time
  3. * Author    : Stephen McNabb
  4. * Creation date : 15th February 1995
  5. * Last update    : 15th February 1995
  6. * Parameters    : Different for each function
  7. * Output    : Different for each function
  8. * Comment    : This source code file takes some of the functions
  9. *          from '\source\basic\' and puts them to use. See
  10. *           the appropriate function in this directory for
  11. *          parameters and outputs
  12. *
  13. *          exit      - uses 'exit.s'
  14. *          cls      - uses 'putchar.s' and escape sequences
  15. *          gchar   - uses 'getchar1.s'
  16. *          pchar   - uses 'putchar.s'
  17. *          ptext      - uses 'puttext.s'
  18. *          line      - uses 'puttext.s'
  19. *          wait    - uses 'getchar2.s'
  20. *
  21. *          This is a handy file to include with each of your
  22. *          own programs. You will notice that on most of the
  23. *          functions the data and address registers are pushed
  24. *          onto the stack at the beginning of the routine and
  25. *          popped back off at the end. This is because the trap
  26. *          functions use the registers themselves and your own
  27. *          data in the registers could become corrupt if you
  28. *          don't save them before performing a trap.
  29.  
  30. * This routine displays a 'Press a key' on the screen and waits
  31. * for a keypress before exiting cleanly from the program
  32.  
  33. exit:    bsr    wait            /wait for a keypress
  34.     move.w    #0,-(sp)        /move exit code to stack
  35.     move.w    #$4c,-(sp)        /use Pterm() function
  36.     trap    #1            /use gemdos
  37.     
  38.  
  39. * This routine clears the screen and places the cursor at the top
  40. * left hand side of the screen. It uses the ESC E sequence
  41.  
  42. cls:    movem.l    d0,-(sp)        /stack register
  43.     move.b    #27,d0            /move escape character to d0
  44.     jsr    pchar            /and display on screen
  45.     move.b    #'E',d0            /move 'E' character to d0
  46.     jsr    pchar            /and display on screen
  47.     movem.l    (sp)+,d0        /unstack register
  48.     rts                /return from subroutine
  49.  
  50.  
  51. * This routine gets a character from the keyboard and stores
  52. * the result in d0
  53.  
  54. gchar:    movem.l    d1-d2/a0-a2,-(sp)    /stack registers
  55.     move.w    #1,-(sp)        /use Cconin() function
  56.     trap    #1            /use gemdos
  57.     addq.l    #2,sp            /tidy up stack
  58.     movem.l    (sp)+,d1-d2/a0-a2    /unstack registers
  59.     rts                /return from subroutine
  60.  
  61.  
  62. * This routine gets a string of characters from the keyboard and
  63. * stores the address of the string in d0
  64.  
  65. gtext:    movem.l    d1-d2/a0-a2,-(sp)    /stack registers
  66.     move.l    #length,-(sp)        /move length of string onto stack
  67.     move.w    #$A,-(sp)        /use Cconrs() function
  68.     trap    #1            /use gemdos
  69.     addq.l    #6,sp            /tidy up stack
  70.     move.l    #string,d0        /load address of string into d0
  71.     movem.l    (sp)+,d1-d2/a0-a2    /unstack registers
  72.     rts                /return from subroutine
  73.  
  74.  
  75. * This routine displays a character stored in d0 on the screen
  76.  
  77. pchar:    movem.l    d0-d2/a0-a2,-(sp)    /stack regi|sters
  78.     move.w    d0,-(sp)        /move character in d0 onto stack
  79.     move.w    #2,-(sp)        /use Cconout() function
  80.     trap    #1            /use gemdos
  81.     addq.l    #4,sp            /tidy up stack
  82.     movem.l    (sp)+,d0-d2/a0-a2    /unstack registers
  83.     rts                /return from subroutine
  84.  
  85.  
  86. * This routine displays a null terminated string on the screen.
  87. * The address of the string must be stored in d0 before using it.
  88.  
  89. ptext:    movem.l    d0-d2/a0-a2,-(sp)    /stack regsiters
  90.     move.l    d0,-(sp)        /move address of string to stack
  91.     move.w    #$9,-(sp)        /use Cconws() function
  92.     trap    #1            /use gemdos
  93.     addq.l    #6,sp            /tidy up stack
  94.     movem.l    (sp)+,d0-d2/a0-a2    /unstack registers
  95.     rts                /return from subroutine
  96.  
  97.  
  98. * This routine displays a carriage return and line feed to the screen
  99.  
  100. line:    movem.l    d0,-(sp)        /stack register
  101.     move.l    #cr,d0            /move carriage return to d0
  102.     jsr    ptext            /and display on screen
  103.     movem.l    (sp)+,d0        /unstack register
  104.     rts                /return from subroutine
  105.  
  106.  
  107. * This routine displays a 'Press a key.' message on the screen
  108. * and waits for a keypress which is not echoed to the screen
  109.  
  110. wait:    movem.l    d0-d2/a0-a2,-(sp)    /stack registers
  111.     move.l    #press,d0        /move 'press-a-key' string to stack
  112.     jsr    ptext            /and display on screen
  113.     move.w    #7,-(sp)        /use Crawcin() function
  114.     trap    #1            /use gemdos
  115.     addq.l    #2,sp            /tidy up stack
  116.     movem.l    (sp)+,d0-d2/a0-a2    /unstack registers
  117.     rts                /return from subroutine
  118.  
  119. *** Program Data ***
  120.  
  121. length:    dc.b    80        /length of string to be read   -+
  122. read:    dc.b    0        /length of string actually read    | keep together
  123. string:    ds.b    81        /string read               -+
  124.  
  125. press:    dc.b    $D,$A,'Press a key',$D,$A,0    /'Press a key' string
  126. cr:    dc.b    $D,$A,0                /carriage return and line feed
  127.  
  128. * Note : $D = Carriage return
  129. *     $A = Line feed
  130.  
  131. *** End of file ***
  132.